package com.atguigu.condition;

import com.atguigu.bean.RainBow;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author gcq
 * @Create 2020-09-22
 */
public class MyImportBeanDefinitonRegistrar implements ImportBeanDefinitionRegistrar {
    /**
     *
     * @param importingClassMetadata 当前类的注解信息
     * @param registry BeanDefnition注册类
     *                 把所有需要添加到容器中的bean 调用
     *                 BeanDefinitionRegistry.registerBeanDefinition手工注册
     */
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        boolean definiton = registry.containsBeanDefinition("color");
        boolean definiton2 = registry.containsBeanDefinition("yellow");
        System.out.println(definiton + "==" + definiton2);
        if (true) {
            System.out.println("bean");
            //执行bean名
            RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(RainBow.class);
            registry.registerBeanDefinition("rainBow",rootBeanDefinition);
        }
    }
}